<%@page pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <%@include file="/WEB-INF/jsp/common/common.jsp"%>
	<script>
    $(function(){
    	$("#insertBtn").click(function(){
    		window.location.href = "${APP_PATH}/proc/add.do";
    	});
    	
    	$("#detailBtn").click(function(){
    		var rows = $('#dataTable').datagrid('getSelections');
    		if ( rows.length == 0 ) {
    			$.messager.alert('系统提示信息', "必须选择查看图片的流程定义信息",'error');
    		} else if ( rows.length > 1 ) {
    			$.messager.alert('系统提示信息', "只能选择一条流程定义信息查看图片",'error');
    		} else {
        		var row = rows[0];
        		window.location.href = "${APP_PATH}/proc/view.do?id="+row.id;
    		}
    	});
    	
    	$("#deleteBtn").click(function(){
    		var rows = $('#dataTable').datagrid('getSelections');
    		if ( rows.length == 0 ) {
    			$.messager.alert('系统提示信息', "必须选择需要删除的流程定义信息",'error');
    		} else {
    			$.messager.confirm('系统提示信息', '删除选择的流程定义信息，是否继续?', function(r){
    				if (r){
	        			var paramObj = {};
	        			
	        			$.each( rows, function(i, row) {
	        				paramObj["pdids["+i+"]"] = row.id;
	        			} );

	        			$.ajax({
	        				type : "POST",
	        				url  : "${APP_PATH}/proc/deleteProcDefs.do",
	        				data : paramObj,
	        				beforeSend : function() {
	        					return true;
	        				},
	        				success : function( r ) {
	        					if ( r.success ) {
	        						$.messager.alert('系统提示信息', "流程定义信息删除成功",'info', function(){
	        							$('#dataTable').datagrid('reload');
	        						});
	        					} else {
	        						$.messager.alert('系统提示信息', "流程定义信息删除失败",'info');
	        					}
	        				}
	        			});
    				}
    			});
    		}
    	});
    });
	</script>
</head>
<body class="easyui-layout">
    <div data-options="region:'center',border:false">
	<table id="dataTable"
	       class="easyui-datagrid"
	       title="流程定义分页查询表格"
		   data-options="
		        fit:true,
		        border:false,
		   		singleSelect:false,
		   		collapsible:false,
		   		fitColumns:true,
		   		rownumbers:true,
		   		url:'${APP_PATH}/proc/pageQuery.do',
		   		method:'get',
				pagination:true,
				pageSize:10,
				toolbar:'#tb'
		   ">
		<thead>
			<tr>
			    <th data-options="field:'id',checkbox:true"></th>
				<th data-options="field:'key',width:100">流程标识</th>
				<th data-options="field:'name',width:100">流程名称</th>
				<th data-options="field:'version',width:100">版本</th>
			</tr>
		</thead>
	</table>
	</div>
	<div id="tb" style="padding:5px;height:auto">
		<div style="margin-bottom:5px">
			<a href="#" id="insertBtn" class="easyui-linkbutton" iconCls="icon-add" plain="true"></a>
			<a href="#" id="deleteBtn" class="easyui-linkbutton" iconCls="icon-remove" plain="true"></a>
			<a href="#" id="detailBtn" class="easyui-linkbutton" iconCls="icon-search" plain="true"></a>
		</div>
	</div>
</body>
</html>
